package handler;

import entity.CourseDO;
import entity.GradeDO;
import service.CourseService;
import service.GradeService;
import service.impl.CourseServiceImpI;
import service.impl.GradeServiceImpI;
import view.CourseView;
import view.GradeView;
import view.UpdateCoursView;
import view.UpdateGradeView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UpdateGradeViewHandler implements ActionListener {

    private UpdateGradeView updateGradeView;
    private GradeView gradeView;

    public UpdateGradeViewHandler(UpdateGradeView updateGradeView, GradeView gradeView) {
        this.updateGradeView = updateGradeView;
        this.gradeView = gradeView;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton = (JButton) e.getSource();
        String text = jButton.getText();
        if ("修改".equals(text)) {
            GradeService gradeService = new GradeServiceImpI();
            GradeDO gradeDO = updateGradeView.buildUpdateGradeDO();
            boolean updateResult = gradeService.update(gradeDO);
            if (updateResult) {
                //重新加载表格
                gradeView.reloadTable();
                updateGradeView.dispose();
            } else {
                JOptionPane.showMessageDialog(updateGradeView, "修改失败");
            }
        }
    }
}
